#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QSlider>
#include <QDialog>


MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    setWindowTitle(tr("Main Window"));

    openAction = new QAction(QIcon(":/images/doc-open"), tr("&Open..."), this);
    openAction->setShortcuts(QKeySequence::Open);
    openAction->setStatusTip(tr("Open an existing file"));
    connect(openAction, &QAction::triggered, this, &MainWindow::open);

    QMenu *file = menuBar()->addMenu(tr("&File"));
    file->addAction(openAction);

    QToolBar *toolBar = addToolBar(tr("&File"));
    toolBar->addAction(openAction);

}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::open()
{
    //建立在栈上的内存，必须使用exec的阻塞方式
    //QDialog dialog;
    //dialog.setWindowTitle(tr("Hello, dialog!"));
    //dialog.exec();
    //dialog.show();//在栈上的变量，会一闪而过的

    //这个需要在.h里面就定义这个对话框指针了，建立在堆上的内存

    //这种形式，关掉主窗口，子窗口自动关闭
    //dialog2=new QDialog(this);
    //这种形式，关掉主窗口，子窗口还存在
    dialog2=new QDialog();
    dialog2->setAttribute(Qt::WA_DeleteOnClose);
    dialog2->show();

}
